<?php

function loadTypeRealByTypePost(){ 
	$type_post = $_POST['type_post'] ? $_POST['type_post'] : 0; 
	if($type_post > 0){
		$list_result = mdGetListTypeRealByTypePost( $type_post );
		$json['list_result'] = $list_result;
	}
	drupal_json_output( $json );
}

function loadDistrictByCity(){
	$city = $_POST['city'] ? $_POST['city'] : 0; 
	if($city > 0){
		$list_result = mdGetListDistrictByCity( $city );
		$json['list_result'] = $list_result;
	}
	drupal_json_output( $json );
}

function loadWardStreetProjectByDistrict(){
	$district = $_POST['district'] ? $_POST['district'] : 0; 
	if($district > 0){
		$list_ward = mdGetListWardByDistrict( $district );
		$list_street = mdGetListStreetByDistrict( $district );
		$list_project = mdGetListProjectByDistrict( $district );
		$json['list_ward'] = $list_ward;
		$json['list_street'] = $list_street;
		$json['list_project'] = $list_project;
	}
	drupal_json_output( $json );
}

function ajaxPostRealestate(){ 
	if($_POST['pr_txt_list_images']){
    $list_image = explode(',' , $_POST['pr_txt_list_images']);
		if(count($list_image) > 0){
			$albumId = mdCreateAlbum($_POST['pr_txt_title'] , '');
			if($albumId > 0){
				foreach ($list_image as $image){
					mdInsertImageToAlbum($image , $albumId);
				}
			}
		}    
	}
    $data = $_POST;
    $data['total_img'] = $list_image ? count($list_image) : 0;
    $data['m_fid'] = $list_image[0] ? $list_image[0] : 0;
    $data['id_album'] = $albumId ? $albumId : 0;    
    $rid = mdInsertRealEstate( $data );
    if( $rid > 0){
        die(print 'ok');
    }
}
